package com.nami.store.api.request.conversation;

import lombok.Data;

import java.io.Serializable;
import java.util.Objects;

/**
 * caffeine 缓存使用
 *
 * @daate 2024-12-18
 */
@Data
public class ConverItem implements Serializable {

    private Long id;

    private String appKey;

    private String userId;

    private String targetId;

    /**
     * 是否免打扰
     */
    private Boolean ifMute;

    /**
     * 是否置顶
     */
    private Boolean ifTop;

    /**
     * c2c :1
     * c2g :2
     */
    private Integer converType;

    private String latestMsgId;

    private String latestMsg;

    private Integer latestUnreadMsgIndex;

    private Integer latestReadMsgIndex;

    private String latestReadMsgId;

    private Long latestReadMsgTime;

    private Long sortTime;

    private Long syncTime;

    private Long topUpdatedTime;

    public ConverItem() {
    }

    /**
     * deep clone
     *
     * @param other
     */
    public ConverItem(ConverItem other) {
        this.id = other.getId();
        this.appKey = other.getAppKey();
        this.userId = other.getUserId();
        this.targetId = other.getTargetId();
        this.ifMute = other.getIfMute();
        this.ifTop = other.getIfTop();
        this.converType = other.getConverType();
        this.latestMsgId = other.getLatestMsgId();
        this.latestMsg = other.getLatestMsg();
        this.latestUnreadMsgIndex = other.getLatestUnreadMsgIndex();
        this.latestReadMsgIndex = other.getLatestReadMsgIndex();
        this.latestReadMsgId = other.getLatestReadMsgId();
        this.latestReadMsgTime = other.getLatestReadMsgTime();
        this.sortTime = other.getSortTime();
        this.syncTime = other.getSyncTime();
        this.topUpdatedTime = other.getTopUpdatedTime();
    }

    // 深拷贝方法
    public ConverItem clone() {
        return new ConverItem(this);
    }


    // redis 缓存存入
    @Override
    public int hashCode() {
        return Objects.hash(appKey, userId, targetId);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        ConverItem that = (ConverItem) obj;
        return Objects.equals(appKey, that.appKey) &&
            Objects.equals(userId, that.userId) &&
            Objects.equals(targetId, that.targetId);
    }

}
